const rq = require('request-promise')
exports.main = async(event, context) => {
  //定义自己的dMdoPIOuHkTQblz2l4RuRWndapiKey4PNaa0r8ydz2edS0QXispyPNBouUEdrZ
  let apiKey = 'xxxxxxxxx', 
    grantType = 'client_credentials',
    secretKey = 'xxxxxxxx',
    url = `https://aip.baidubce.com/oauth/2.0/token`

   return  await rq({
        method: 'POST',
        url,
        form: {
          "grant_type": grantType,
          "client_secret": secretKey,
          "client_id": apiKey
        },
        json: true
      }).then(data=>{
        return Promise.resolve({
          code: 0,
          data,
          info: '操作成功！'
        })
     }).catch(error=>{
       return Promise.resolve({
         code: -1,
         errMsg: error,
       })
      })
}